package com.mall.db.api;

import cn.hutool.core.convert.Convert;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.mall.db.mapper.UmsAdminRoleRelationMapper;
import com.mall.db.mapper.UmsRoleMenuRelationMapper;
import com.mall.domain.UmsRoleMenuRelation;
import com.mall.interface1.api.UmsRoleMenuRelationApi;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@DubboService
public class UmsRoleMenuRelationApiImpl implements UmsRoleMenuRelationApi {
    @Autowired
    private UmsRoleMenuRelationMapper mapper;
    @Override
    public List<UmsRoleMenuRelation> query(List<Long> ids) {
        LambdaQueryWrapper<UmsRoleMenuRelation> qw = new LambdaQueryWrapper<>();
        qw.in(UmsRoleMenuRelation::getRoleId,ids);
       return mapper.selectList(qw);
    }

    @Override
    public void save(Integer[] menuIds, Integer roleId) {
        for (Integer menuId : menuIds) {
            UmsRoleMenuRelation s = new UmsRoleMenuRelation();
            s.setRoleId(Convert.toLong(roleId));
            s.setMenuId(Convert.toLong(menuId));
            mapper.insert(s);
        }
    }

    @Override
    public List<UmsRoleMenuRelation> findById(Integer roleId) {
        LambdaQueryWrapper<UmsRoleMenuRelation> q = new LambdaQueryWrapper<>();
        q.eq(UmsRoleMenuRelation::getRoleId,roleId);
        return mapper.selectList(q);
    }

    @Override
    public List<UmsRoleMenuRelation> listIds(Integer[] ids) {
        LambdaQueryWrapper<UmsRoleMenuRelation> qw = new LambdaQueryWrapper<>();
        qw.in(UmsRoleMenuRelation::getRoleId, ids);
        return mapper.selectList(qw);
    }
}
